package com.test.daily.leetcode.y2022.m01.day0109;

/**
 * @author Tom on 2022/1/9
 */
public class SlowestKey {
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int N = releaseTimes.length;
        int maxTime = 0;
        char maxKey = keysPressed.charAt(0);
        for(int i = 1; i < N; i++){
            if(maxTime < releaseTimes[i] - releaseTimes[i-1]){
                maxTime = releaseTimes[i] - releaseTimes[i-1];
                maxKey = keysPressed.charAt(i);

            }else if(maxTime == releaseTimes[i] - releaseTimes[i-1]){
                if(keysPressed.charAt(i) > maxKey){
                    maxKey = keysPressed.charAt(i);
                }
            }
        }
        return maxKey;
    }
}
